package com.gomore.opple.utils;

import android.app.Activity;
import android.content.Context;

import com.gomore.opple.R;
import com.gomore.opple.widgets.dialog.ConfirmDialog;
import com.gomore.opple.widgets.dialog.LoadingDialog;

public class DialogUtils {


    private static LoadingDialog mLoadingDialog = null;
    private static ConfirmDialog confirmDialog = null;


    public static void showLoadingDialog(Context context, String strMessageID) {
        if (mLoadingDialog != null && !mLoadingDialog.isShowing()) {
            mLoadingDialog = null;
        }
        if (mLoadingDialog == null || mLoadingDialog.isContextRelease()) {
            mLoadingDialog = new LoadingDialog(context, R.layout.dialog_loading, strMessageID, null, false);
        }
        if (!mLoadingDialog.isShowing())
            mLoadingDialog.show();
    }

    public static void showLoadingDialog(Context context) {
        if (mLoadingDialog != null && !mLoadingDialog.isShowing()) {
            mLoadingDialog = null;
        }
        if (mLoadingDialog == null || mLoadingDialog.isContextRelease()) {
            mLoadingDialog = new LoadingDialog(context, R.layout.dialog_loading, null, null, false);
            mLoadingDialog.setHideMessage();
        }
        if (!mLoadingDialog.isShowing())
            mLoadingDialog.show();
    }

    public static void closeLoadingDialog() {
        if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
            mLoadingDialog.dismiss();
            mLoadingDialog = null;
        }
    }

    public static void showConfirmDialog(Activity context, ConfirmDialog.onYesOnclickListener yesOnclickListener, ConfirmDialog.onNoOnclickListener noOnclickListener, String title, String message) {

        if (confirmDialog != null && !confirmDialog.isShowing()) {
            confirmDialog = null;
        }

        confirmDialog = new ConfirmDialog(context);
        confirmDialog.setMessage(message);
        confirmDialog.setTitle(title);
        confirmDialog.show();

        if (yesOnclickListener == null) {
            confirmDialog.hideConfirmButton();
        } else {
            confirmDialog.setYesOnclickListener("确定", yesOnclickListener);
        }
        if (noOnclickListener == null) {
            confirmDialog.hideCancelButton();
        } else {
            confirmDialog.setNoOnclickListener("取消", noOnclickListener);
        }
    }

    public static void cancel() {
        if (confirmDialog != null) {
            confirmDialog.cancel();
        }
    }
}
